package com.example.demo1


inline fun <A> Kind<Option2.K,A>.unwrap():Option2<A> = this as Option2<A>

sealed class Option2<out A>:Kind<Option2.K,A>{
    object K
}

data class Some<V>(val value:V):Option2<V>()
object None:Option2<Nothing>()


object OptionMonad:Monad<Option2.K>{
    override fun <A> pure(a: A): Kind<Option2.K, A> {
        return Some(a)
    }

    override fun <A, B> Kind<Option2.K, A>.flatMap(f: (A) -> Kind<Option2.K, B>): Kind<Option2.K, B> {
        return when(val oa = this){
            is Some -> f(oa.value)
            else -> None
        }
    }

}














